﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.ProcessManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.ProcessManagement.ProcessResultsVMs
{
    public partial class ProcessResultsListVM : BasePagedListVM<ProcessResults_View, ProcessResultsSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ProcessResults_View>> InitGridHeader()
        {
            return new List<GridColumn<ProcessResults_View>>{
                
                this.MakeGridHeader(x => x.ProcessResults_Rotue).SetTitle(@Localizer["Page.工艺路线"].Value),
                this.MakeGridHeader(x => x.ProcessResults_Op).SetTitle(@Localizer["Page.所属工序"].Value),
                this.MakeGridHeader(x => x.ProcessResults_OpCode).SetTitle(@Localizer["Page.工序编码"].Value),
                this.MakeGridHeader(x => x.ProcessResults_TagId).SetTitle(@Localizer["Page.变量"].Value),
                this.MakeGridHeader(x => x.ProcessResults_TagName).SetTitle(@Localizer["Page.变量名称"].Value),
                this.MakeGridHeader(x => x.ProcessResults_DataName).SetTitle(@Localizer["Page.数据名称"].Value),
                this.MakeGridHeader(x => x.ProcessResults_Unit).SetTitle(@Localizer["Page.单位"].Value),
                this.MakeGridHeader(x => x.ProcessResults_UpperLimit).SetTitle(@Localizer["Page.上限"].Value),
                this.MakeGridHeader(x => x.ProcessResults_LowerLimit).SetTitle(@Localizer["Page.下限"].Value),
                this.MakeGridHeader(x => x.ProcessResults_ActiveLimit).SetTitle(@Localizer["Page.激活上下限"].Value),
                this.MakeGridHeader(x => x.ProcessResults_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ProcessResults_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ProcessResults_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ProcessResults_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ProcessResults_View> GetSearchQuery()
        {
            var query = DC.Set<ProcessResults>()
                
                .CheckEqual(Searcher.RotueId, x=>x.RotueId)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.OpCode, x=>x.OpCode)
                .CheckEqual(Searcher.TagId, x=>x.TagId)
                .CheckContain(Searcher.TagName, x=>x.TagName)
                .CheckContain(Searcher.DataName, x=>x.DataName)
                .CheckContain(Searcher.Unit, x=>x.Unit)
                .CheckEqual(Searcher.UpperLimit, x=>x.UpperLimit)
                .CheckEqual(Searcher.LowerLimit, x=>x.LowerLimit)
                .CheckEqual(Searcher.ActiveLimit, x=>x.ActiveLimit)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ProcessResults_View
                {
				    ID = x.ID,
                    
                    ProcessResults_Rotue = x.Op.Routie.RoutingCode,
                    ProcessResults_Op = x.Op.OpCode,
                    ProcessResults_OpCode = x.Op.OpCode,
                    ProcessResults_TagId = x.TagId,
                    ProcessResults_TagName = x.Tag.TagName,
                    ProcessResults_DataName = x.DataName,
                    ProcessResults_Unit = x.Unit,
                    ProcessResults_UpperLimit = x.UpperLimit,
                    ProcessResults_LowerLimit = x.LowerLimit,
                    ProcessResults_ActiveLimit = x.ActiveLimit,
                    ProcessResults_CreateTime = x.CreateTime,
                    ProcessResults_UpdateTime = x.UpdateTime,
                    ProcessResults_CreateBy = x.CreateBy,
                    ProcessResults_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ProcessResults_View: ProcessResults
    {
        
        public string ProcessResults_Rotue { get; set; }
        public string ProcessResults_Op { get; set; }
        public string ProcessResults_OpCode { get; set; }
        public long? ProcessResults_TagId { get; set; }
        public string ProcessResults_TagName { get; set; }
        public string ProcessResults_DataName { get; set; }
        public string ProcessResults_Unit { get; set; }
        public decimal? ProcessResults_UpperLimit { get; set; }
        public decimal? ProcessResults_LowerLimit { get; set; }
        public bool? ProcessResults_ActiveLimit { get; set; }
        public DateTime? ProcessResults_CreateTime { get; set; }
        public DateTime? ProcessResults_UpdateTime { get; set; }
        public string ProcessResults_CreateBy { get; set; }
        public string ProcessResults_UpdateBy { get; set; }

    }

}